<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\controller\article;

use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\article\VipLists as ArticleLists;
use app\adminapi\logic\article\lpd;
use app\adminapi\logic\article\VipLogic as ArticleLogic;
use app\common\model\article\Procure;
use app\common\model\article\Vip;


use app\common\model\article\Vip as Article;
use app\common\model\article\Xiaoxi;
use app\common\model\qualifications\Qualifications;
use app\common\model\user\User;
use app\common\model\user\UserAuth;
use think\facade\Db;

use think\facade\Queue;

class VipController extends BaseAdminController
{


    public function addsp()
    {
        $params=$this->request->post();
        $params["user_id"]=(new Qualifications())->where("id","=",$params["q_id"])->value("user_id");
        $params["contacts"]=json_encode($params["contacts"]);
        $shuju=[
            'name' => $params['name'],
            'chuangjiantime'=>time(),
            'user_id' => $params['user_id'] ?? '',
            'contacts' => $params['contacts'] ?? '', //作者
            'sort' => $params['sort'] ?? 1000, // 排序
            'specifications' => $params['specifications'], // 文章摘要
            'producer' => $params['producer'] ?? 0,
            'fming' => $params['fming'],
            'start' => $params['start']??1,
            'xqxx'=>$params['xqxx'],
            'type'=>$params['type'],
            'q_id'=>$params['q_id'],
            'ycxq'=>json_encode($params['ycxq']),

        ];
        $app=new lpd();

      $rtn=  $app->run( $params['name']);
    /*    dump( $params['name']);*/
        $responseObject = json_decode($rtn);

       if ($responseObject->conclusion=='不合规'){

        return $this->success('操作失败', ['data' =>'字符违法' ], 0, 1);
       }
        $newProcureInstance = Procure::create($shuju);
        if ($newProcureInstance) {
            Queue::push('app\job\ArticleLogicJob', $params,"lpd");

            return $this->success('操作成功', ['data' => 1], 1, 1);
        } else {
            // 创建失败
            echo "Create failed!";
        }


        return $this->success('添加成功', ["data"=>1], 1, 1);



    }


    public function ceshi333()

    {


        $openid = 'oqdWs6HLYWUNurbwYzSk3Fka6Jr8';
        $template_id = 'us9omVgOjXIkJHDNYwoLItdafZfu4L3ShqN5YFI9ke4';

        $data = [
            'thing2'=> '山东盛悦科技',
            'character_string8'=> 'keyword1',
        ];
        $res = $this->template($openid,$template_id,$data);
        print_r($res);
    }

//发送微信模版消息
    public function template($openid,$template_id,$data,$url='',$miniprogram=['appid'=>'','pagepath'=>''])
    {
        $config = [
            'app_id' => 'wxaae9936c4891bea0',
            'secret' => 'a018f583ad80711396355269aee3ae71',
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',
        ];
        $app = Factory::officialAccount($config);
        return $app->template_message->send([
            'touser' => $openid,
            'template_id' => $template_id,
            'url' => $url,
            'miniprogram' => $miniprogram,
            'data' => $data,
        ]);
    }
    /**
     * @notes  查看资讯列表
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 9:47
     */
    public function lists()
    {
        return $this->dataLists(new ArticleLists());
    }

    /**
     * @notes  添加资讯
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 9:57
     */
    public function add()
    {
        $params = $this->request->post();
           ArticleLogic::add($params);
           return $this->success('添加成功', ["data"=>1], 1, 1);
    }

    /**
     * @notes  编辑资讯
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 10:12
     */
    public function edit()
    {
        $params = $this->request->post();
        $result = ArticleLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(ArticleLogic::getError());
    }

    /**
     * @notes  删除资讯
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 10:17
     */
    public function delete()
    {
        $params = $this->request->post();
         Db::name("vip")->where("id","=",$params['id'])->delete();
        return $this->success('删除成功', [], 1, 1);
    }

    /**
     * @notes  资讯详情
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 10:15
     */
    public function detail()
    {
        $params = $this->request->get();

        return $this->data((new Vip())->where("id","=",$params['id'])->findOrEmpty()->toArray());
    }


    /**
     * @notes  更改资讯状态1
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/22 10:18
     */
//    public function updateStatus()
//    {
//        $params = (new ArticleValidate())->post()->goCheck('status');
//        $result = ArticleLogic::updateStatus($params);
//        if (true === $result) {
//            return $this->success('修改成功', [], 1, 1);
//        }
//        return $this->fail(ArticleLogic::getError());
//    }


}